<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>${systemName}</title>
    <meta name="description" content="${systemName}">
    <meta name="author" content="stylefeng">

    <link rel="stylesheet" href="${ctxPath}/assets/common/layui/css/layui.css"/>
    <link href="${ctxPath}/assets/common/plugins/ztree/zTreeStyle.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div id="deptForm" class="layui-fluid">
    <div class="layui-row" style="margin-top:15px;background: #f2f7f8;padding: 20px;">
        <ul id="zTree" class="ztree"></ul>
    </div>
    <div class="layui-row" style="background: #CFD4D5;padding: 10px;">
        <div style="text-align: center;">
            <button class="layui-btn layui-btn-sm" id="saveButton">保存</button>
            <button class="layui-btn layui-btn-sm layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </div>
</div>

@/* 加入contextPath属性和session超时的配置 */
<script type="text/javascript">
    var Feng = {
        ctxPath: "",
        addCtx: function (ctx) {
            if (this.ctxPath === "") {
                this.ctxPath = ctx;
            }
        }
    };
    Feng.addCtx("${ctxPath}");
</script>
<script type="text/javascript" src="${ctxPath}/assets/common/plugins/jquery/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/common/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/common/js/common.js"></script>

<!--其他插件js-->
<script type="text/javascript" src="${ctxPath}/assets/common/plugins/ztree/jquery.ztree.all.min.js"></script>

<script type="text/javascript">

    layui.use(['ztree','ax','layer'], function () {
        var $ZTree = layui.ztree;
        var $ax = layui.ax;
        var layer = layui.layer;
        var ZTreeDlg = {
            index: parent.layer.getFrameIndex(window.name)
        };
        
        var layerIndex;
        $("#saveButton").bind("click", function () {
        	var ids = Feng.zTreeCheckedNodes("zTree");
			$.ajax({
				url : Feng.ctxPath + "/role/setAuthority",
				data : {
					"ids" : ids,
					"roleId" : "${roleId}",	
				},
				type : 'post',
				dataType : 'json',
				beforeSend: function (request) {
					layerIndex = layer.load(2, 
						{
							time: 30*1000
							,content: '权限更新中...'
							, success: function (layero) {
						        layero.find('.layui-layer-content').css({
						            'padding-left': '40px',
						            'width': '100px'
						        });
					    	}
						}
					);
				},
				success : function(data) {
					layer.close(layerIndex);
					Feng.success("分配角色成功!");
	                parent.layer.close(ZTreeDlg.index);
				},
				error : function(data) {
					 Feng.error("分配角色失败!" + data.responseJSON.message + "!");
				}
	        });
        });
        
        var setting = {
            check: {
                enable: true,
                chkboxType: {
                    "Y": "ps",
                    "N": "ps"
                }
            },
            data: {
                simpleData: {
                    enable: true
                }
            }
        };

        var ztree = new $ZTree("zTree", "/menu/menuTreeListByRoleId/${roleId}");
        ztree.setSettings(setting);
        ztree.init();
    });

</script>

</body>

</html>
